package orangeScript.android.helper;

import orangeScript.language.FunctionValue;
import orangeScript.language.RawValue;
import orangeScript.language.StringValue;
import orangeScript.language.Value;
import orangeScript.language.exceptions.UserDefinedException;
import android.view.View;
import android.view.View.OnClickListener;

public class ViewOnClickListener implements OnClickListener {

	private final FunctionValue fv;
	
	public ViewOnClickListener(Value fv) {
		if ((fv == null) || !(fv instanceof FunctionValue)) {
			throw new UserDefinedException(new StringValue("Invalid arguments")); 
		}
		this.fv = (FunctionValue)fv;
	}

	@Override
	public void onClick(View v) {
		RawValue rv_v = RawValue.get(v);
		Value[] args = new Value[]{rv_v};
		fv.call(args, null);
	}

}
